package com.itheima.day05.zuoye.ZuoYe1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;

public class BigDecimalTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 创建集合，存入手机对象
        ArrayList<Phone> list = new ArrayList<>();
        list.add(new Phone("华为Mate50Pro", 6739.00));
        list.add(new Phone("vivo X Fold2", 8999.00));
        list.add(new Phone("iphone14 128G", 5999.00));
        list.add(new Phone("vivo iQOO11", 4399.00));
        list.add(new Phone("荣耀90 5G", 2799.00));
        list.add(new Phone("红米K60E", 1999.00));
        list.add(new Phone("华为nove 11", 2799.00));
        list.add(new Phone("小米13 5G", 4299.00));


        while (true) {
            System.out.println("请输入您想购买的名称：");
            String brand = sc.next();
            Phone phone = null;
            boolean flag = false;
            for (int i = 0; i < list.size(); i++) {
                // 遍历集合，找到那个手机
                // 【此处补充代码】！！！

                // 判断是否有这个手机
                if (list.get( i).getBrand().equals(brand)) {
                    flag = true;
                    phone = list.get(i);
                }
            }
            if (flag) {
                // 定义钢化膜价格
                // 【此处补充代码】！！！
                double ganghuamo = 9.9;

                System.out.println("请输入优惠方案：\n\t1-满3000打98折 \n\t2-以旧换新立减500");
                int choose = sc.nextInt();
                // 计算手机和钢化膜总价
                // 【此处补充代码】！！！
                BigDecimal phoneprice = BigDecimal.valueOf(phone.getPrice());
                BigDecimal ghmprice = BigDecimal.valueOf(ganghuamo*2);
                BigDecimal total = phoneprice.add(ghmprice);
                BigDecimal one = BigDecimal.valueOf(1);
                // 判断选择哪种方案
                switch (choose) {
                    case 1:
                        // 满3000打98折
                        // 【此处补充代码】！！
                        if(phone.getPrice()>=3000){
                        BigDecimal youhui = BigDecimal.valueOf(0.98);
                        BigDecimal discount = total.multiply(youhui);
                        System.out.println("手机与两个钢化膜总价为：" + discount);
                        break;
                        }else{
                            System.out.println("手机价格未满3000元，自动计算以旧换新价格");
                        }
                    case 2:
                        // 以旧换新立减500
                        // 【此处补充代码】！！！
                        BigDecimal youhui2 = BigDecimal.valueOf(500);
                        BigDecimal discount2 = total.subtract(youhui2);
                        System.out.println("手机与两个钢化膜总价为：" + discount2);
                        break;
                }
                // 【此处补充代码】！！！
                System.out.println("恭喜你，购买成功！");
                return;
            } else {
                System.out.println("很抱歉，没有此手机！");
                return;
            }
        }
    }
}
